//
//  PaymentEngineMiddleware.h
//  Middleware-iOSLibrary
//
//  Created by USAePay on 7/30/15.
//  Copyright (c) 2015 USAePay. All rights reserved.
//  Description: Use this class to communicate with the hardware devices.
//

#import <Foundation/Foundation.h>
#import "PaymentEngineTransactionResponse.h"
#import <UIKit/UIKit.h>

@protocol PaymentEngineMiddlewareDelegate <NSObject>

@required

/*!
    @brief Delegate method for startTransaction. 
    @param transResponse - Contains all the transaction response info from the gateway
 */
-(void)transactionComplete :(PaymentEngineTransactionResponse *)transResponse;
@optional

/*!
    @brief Delegate method for device connected. The method gets called when the device is connected
 */
-(void)deviceConnected;

/*!
  @brief Delegate method for device disconnected. The method gets called when the device is disconnected
 */
-(void)deviceDisconnected;

/*!
  @brief Call this delegate method when the receipt is returned from the gateway
  @param receiptValue - Contains all the necessary data for a receipt
 */
-(void)returnReceiptCompleted :(NSString *)receiptValue;

/*!
    @brief Delegate method, it will get call when we start to update the terminal config
 */
-(void)startUpdatingTerminal;

/*!
  @brief Delegate method, it will get call once we finish updating all the terminal config
 */
-(void)updateTerminalConfigComplete;

/*!
    @briefThis is a call back method when the signature is captured
    @param transResponse - Contains all the transaction information returned from the server
 */
-(void)captureSignatureComplete :(PaymentEngineTransactionResponse *)transResponse;

/*!
    @brief Delegate method for getMerchantCapabilities
    @param merchantCapDict - Dictionary that holds information about the merchant and the features they support
 */
-(void)getMerchantCapabilitiesComplete: (NSDictionary *)merchantCapDict;

/*!
 @brief Delegate method for readDeviceInfo
 @param deviceInfoDict - Dictionary that holds information about the merchant and the features they support
 */
-(void) readDeviceInfoComplete :(NSDictionary *)deviceInfoDict;

/*!
 * The delegate method gets called when adjust transaction is completed
 * @param transResponse - Contains all the transaction information returned from the gateway
 */
-(void)adjustTranstionComplete :(PaymentEngineTransactionResponse *)transResponse;

/*!
 @brief Delegate method for print, this is an optional delegate method if user wants to see print error
 @param msg - returns the error message
 */
-(void)printCompleted:(NSString *)msg;

/*
 @brief delegate method, gets call once barcode scan is completed
 @param barcode - returns the scanned barcode
 @param errorMsg - If there is an error, return what the error is,
 */
-(void)barcodeScanCompleted :(NSString *)barcode :(NSString *)errorMsg;

/*
 @brief delegate method, gets call once we obtain a timeout duration from the device
 @param seconds - returns the timeout duration in seconds
 */
-(void)getDeviceTimeoutCompleted :(int) seconds;

@end

@interface PaymentEngineMiddleware : NSObject

+ (PaymentEngineMiddleware *) getInstance;

@property(nonatomic, weak) id<PaymentEngineMiddlewareDelegate> delegate;

//------------------------------Device Methods------------------------------

/*!
    @brief This method must be called before starting any transaction. Use it to connect to a device.
    @param deviceName The name of the device such as icmp or castle
    @param setDelegate Sets to self
 
 */
-(void)setDevice :(NSString *)deviceName :(id)setDelegate;

/*! @brief Returns true if the device is online, false otherwise */
-(BOOL)isDeviceOnline;

/*! @brief Disconnect the terminal from the device */
-(void)disconnectDevice;

/*! @brief Connects the terminal to the device */
-(void)connectDevice;

/*! @brief (Not supported on MP200) This method takes the icmp device to go online */
-(void)goOnline;

/*! @brief (Not supported on MP200) This method takes the icmp device to go offline */
-(void)goOffline;

/*! @brief Deprecated in v2.3.5 - Returns all the information related to the device such as firmware, device model and etc... */
-(NSDictionary *)getDeviceInfo;

/*!
        @brief Sends a command to the device to retrieve a list of device information such as battery level, firmware, and etc..
        @delegate Callback method - readDeviceInfoComplete :(NSDictionary *)deviceInfo
 */
-(void)readDeviceInfo;

/*! @brief Cancels a transaction that is still in progress */
-(void)cancelTransaction;

/*!
  @brief Call this method to start printing text
 @param text - The string value to print
  @detail only available on V3 terminal with printer capability
 */
-(void) printText: (NSString *)text;

/*!
 @brief Call this method to start printing image
 @param image - The image you want to print in PNG format
 @detail only available on V3 terminal with printer capability
  @delegate Callback method -(void)printCompleted:(NSString *)msg
 */
-(void)printImage :(UIImage *)image;

/*!
 @brief Call this method to start barcode scanning
 @param timeOut - Barcode timeout in seconds
 @delegate Callback method - barcodeScanCompleted :(NSString *)barcode
 */
-(void)startBarcodeScan :(int) timeOut;

/*!
 @brief Call this method to manually display image on the castle device
 @param imgType - a list of image enum type can be found in PaymentEngineMiddlewareSettings.h
 @param second - Image Timeout in seconds
 */
-(void)displayImg :(DisplayImageType )imgType timeOut:(int)second;

/*!
 @brief Call this method to manually set device timeout
 @param second - Timeout in seconds
 */
-(void)setDeviceTimeout :(int)second;

/*!
 @brief Call this method to manually get the device timeout duration
 @delegate Callback method - getDeviceTimeoutCompleted :(int) seconds
 */
-(void)getDeviceTimeout;

//------------------------------Gateway Methods------------------------------

/*!
        @brief Use the method whenever a transaction is ready to be process
        @param holdTransInfo - A NSMutableDicitonary that holds all the transaction info
 */
-(void)startTransaction :(NSMutableDictionary *)holdTransInfo;

/*!
        @brief Use the method to capture a signature
        @param holdCaptureInfo - Contains all the transaction info and signature image in base64 encoded format
 
 */
-(void)captureSignature :(NSMutableDictionary *)holdCaptureInfo;

/*!
        @brief Adjust the transaction amount that is already processed, user can use this method to add tips to existing transaction or adjust the transaction amount
        @paramd holdTransInfo - A NSMutableDictionary that holds all the transaction info
 */
-(void)adjustTransaction :(NSMutableDictionary *)holdTransInfo;

/*!
        @brief Use the method to obtain receipt from gateway
        @param receiptDict - Contains all the necessary information for a receipt
 */
-(void)getReceipt :(NSDictionary *)receiptDict;

/*!
        @brief Use the method to obtain merchant's capability
        @param autoUpdateConfigs - Setting it to true will automatically updates the merchant capaiblity in the device if the device is connected
 */
-(void)getMerchantCapabilities :(BOOL)autoUpdateConfigs;


@end
